package com.im.service.investPlan.smo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.im.MDA;
import com.im.service.dto.BaseException;
import com.im.service.dto.FixAsset;
import com.im.service.dto.FundPlan;
import com.im.service.dto.FundSource;
import com.im.service.dto.Funds;
import com.im.service.dto.InvestPlan;
import com.im.service.dto.InvestStatic;
import com.im.service.dto.PageQuery;
import com.im.service.dto.PlanDeclareSet;
import com.im.service.dto.ProjectStage;
import com.im.service.fixAsset.dao.IFixAssetQueryDao;
import com.im.service.fundPlan.dao.IFundPlanQueryDAO;
import com.im.service.fundPlan.smo.IFundPlanManageQuerySMO;
import com.im.service.investPlan.dao.IInvestPlanQueryDAO;
import com.im.service.projectInfo.dao.IFundSourceQueryDAO;
import com.im.service.projectInfo.dao.IImplementProjQueryDAO;
import com.im.service.projectInfo.smo.ProjectInfoQuerySMOImpl;
import com.im.util.JsonUtil;
import com.im.util.ListUtil;
import com.im.util.StringUtil;
import com.im.viewmodel.fundPlan.FileVo;
import com.im.viewmodel.fundPlan.FundDetailVo;
import com.im.viewmodel.fundPlan.InvestPlanRspVo;

import net.sf.json.JSONObject;

@Service
public class InvestPlanQuerySMOImpl implements IInvestPlanQuerySMO {

	// private static final Logger logger =
	// LogManager.getLogger(InvestPlanQuerySMOImpl.class);
	@Autowired
	private IInvestPlanQueryDAO investPlanQueryDAO;
	@Autowired
	private IFundSourceQueryDAO fundSourceQueryDAO;
	@Autowired
	private IFundPlanQueryDAO fundPlanQueryDAO;
	@Autowired
    private ProjectInfoQuerySMOImpl projectInfoQuerySMO;
	@Autowired
    private IFundPlanManageQuerySMO fundPlanManageQuerySMO;
	@Autowired
	private IImplementProjQueryDAO implementProjQueryDAO;
	@Autowired
	private IFixAssetQueryDao fixAssetQueryDao;
	
	@Override
	public PageQuery<PlanDeclareSet> queryInvestPlanSetList(String inJson) {

		PageQuery<PlanDeclareSet> page = JsonUtil.jsonToBean(inJson, PageQuery.class);
		PlanDeclareSet investPlanSet = JsonUtil.jsonToBean(inJson, PlanDeclareSet.class);

		Map<String, Object> param = new HashMap<String, Object>();
		param.put("investPlanSet", investPlanSet);
		param.put("page", page);
		PageHelper.startPage(page.getPageNumber(), page.getPageSize());

		List<PlanDeclareSet> planDeclareSets = investPlanQueryDAO.queryInvestPlanSetList(param);
//		for (PlanDeclareSet planSet : planDeclareSets) {
//			InvestPlan inPlan = new InvestPlan();
//			inPlan.setInvestPlanId(planSet.getDeclareRelaObj());
//			Map<String, Object> paramMap = new HashMap<String, Object>();
//			paramMap.put("investPlan", inPlan);
//			InvestPlan investPlan = investPlanQueryDAO.queryInvestPlanDetail(paramMap);
//			planSet.setImpleProjId(investPlan.getImpleProjId());
//			planSet.setImpleProjName(investPlan.getImpleProjName());
//		}

		page.setRows(planDeclareSets);
		page.setTotalPages(((Page<PlanDeclareSet>) planDeclareSets).getPages());
		page.setTotal(((Page<PlanDeclareSet>)planDeclareSets).getTotal());
		return page;
	}

	@Override
	public PageQuery<InvestPlan> queryInvestPlanList(String inJson, List<String> typelist) {
		PageQuery<InvestPlan> page = JsonUtil.jsonToBean(inJson, PageQuery.class);
		InvestPlan iPlan = JsonUtil.jsonToBean(inJson, InvestPlan.class);
		// iPlan.setStatusCd(MDA.FUND_PLAN_STATUS_CD_WAIT);
		String staffCode = JsonUtil.obtainValueFromJsonObject(inJson, "staffCode");
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("investPlan", iPlan);
		param.put("page", page);
		param.put("typelist", typelist);
		/*
		 * if (typelist.size() > 1) param.put("staffCode", staffCode);
		 */

		PageHelper.startPage(page.getPageNumber(), page.getPageSize());

		List<InvestPlan> investPlans = investPlanQueryDAO.queryInvestPlanList(param);
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_INVEST);// 投资计划

		for (InvestPlan investPlan : investPlans) {

			fundSource.setFundSourceObj(investPlan.getInvestPlanId());
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
			for (FundSource fs : fundSourceList) {
				BigDecimal b = new BigDecimal(fs.getFundVal());

				switch (fs.getFundSourceType()) {
				case "10":
					// 资金单位：万元
					if (fs.getFundVal() != null) {
						investPlan.setBuFund(b.toPlainString() + "");
					}
					break;
				case "20":
					if (fs.getFundVal() != null) {
						investPlan.setShengFund(b.toPlainString() + "");
					}
					break;
				case "30":
					if (fs.getFundVal() != null) {
						investPlan.setGaoFund(b.toPlainString() + "");
					}
					break;
				case "40":
					if (fs.getFundVal() != null) {
						investPlan.setShiFund(b.toPlainString() + "");
					}
					break;
				case "50":
					if (fs.getFundVal() != null) {
						investPlan.setQiFund(b.toPlainString() + "");
					}
					break;
				default:
					break;
				}
			}
			Double total = Double.valueOf(investPlan.getBuFund() == null ? "0" : investPlan.getBuFund())
					+ Double.valueOf(investPlan.getShengFund() == null ? "0" : investPlan.getShengFund())
					+ Double.valueOf(investPlan.getGaoFund() == null ? "0" : investPlan.getGaoFund())
					+ Double.valueOf(investPlan.getShiFund() == null ? "0" : investPlan.getShiFund())
					+ Double.valueOf(investPlan.getQiFund() == null ? "0" : investPlan.getQiFund());
			investPlan.setTotal(total);
			Map<String, Object> paramfile = new HashMap<String, Object>();
			paramfile.put("uploadObjId", investPlan.getInvestPlanId());
			paramfile.put("uploadObjType", "150");
			List<FileVo> files = fundPlanQueryDAO.queryFileListUploadsByCond(paramfile);
			investPlan.setFiles(files);
		}
		page.setRows(investPlans);
		page.setTotalPages(((Page<InvestPlan>) investPlans).getPages());
		page.setTotal(((Page<InvestPlan>)investPlans).getTotal());
		return page;
	}

	@Override
	public InvestPlan queryInvestPlanDetail(String inJson) {
		String investPlanId = JsonUtil.obtainValueFromJsonObject(inJson, "investPlanId");
		InvestPlan inPlan = new InvestPlan();
		inPlan.setInvestPlanId(investPlanId);
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("investPlan", inPlan);
		InvestPlan investPlan = investPlanQueryDAO.queryInvestPlanDetail(paramMap);
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_ADD);// 投资计划
		fundSource.setFundSourceObj(investPlanId);
		List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
		for (FundSource fs : fundSourceList) {
			switch (fs.getFundSourceType()) {
			case "10":
				// 资金单位：万元
				if (fs.getFundVal() != null) {
					investPlan.setBuFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			case "20":
				if (fs.getFundVal() != null) {
					investPlan.setShengFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			case "30":
				if (fs.getFundVal() != null) {
					investPlan.setGaoFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			case "40":
				if (fs.getFundVal() != null) {
					investPlan.setShiFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			case "50":
				if (fs.getFundVal() != null) {
					investPlan.setQiFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			case "60":
				if (fs.getFundVal() != null) {
					investPlan.setOtherFund(Double.valueOf(fs.getFundVal()) + "");
				}
				break;
			default:
				break;
			}
		}
		Double total = Double.valueOf(investPlan.getBuFund() == null ? "0" : investPlan.getBuFund())
				+ Double.valueOf(investPlan.getShengFund() == null ? "0" : investPlan.getShengFund())
				+ Double.valueOf(investPlan.getGaoFund() == null ? "0" : investPlan.getGaoFund())
				+ Double.valueOf(investPlan.getShiFund() == null ? "0" : investPlan.getShiFund())
				+ Double.valueOf(investPlan.getQiFund() == null ? "0" : investPlan.getQiFund())
				+ Double.valueOf(investPlan.getOtherFund() == null ? "0" : investPlan.getOtherFund());

		investPlan.setTotal(total);
		investPlan.setFundSource(queryProjectAndTotalFoundSource(investPlan.getImpleProjId(), "10"));
		// 下达文件
		Map<String, Object> paramfile = new HashMap<String, Object>();
		paramfile.put("uploadObjId", investPlan.getInvestPlanId());
		paramfile.put("uploadObjType", "150");
		List<FileVo> files = fundPlanQueryDAO.queryFileListUploadsByCond(paramfile);
		investPlan.setFiles(files);
		return investPlan;
	}

	@Override
	public PlanDeclareSet queryInvestPlanSetDetail(Map<String, Object> param) {
//		PlanDeclareSet planSet = investPlanQueryDAO.queryInvestPlanSetDetail(param);
//		InvestPlan inPlan = new InvestPlan();
//		inPlan.setInvestPlanId(planSet.getDeclareRelaObj());
//		Map<String, Object> paramMap = new HashMap<String, Object>();
//		paramMap.put("investPlan", inPlan);
//		InvestPlan investPlan = investPlanQueryDAO.queryInvestPlanDetail(paramMap);
//		planSet.setImpleProjId(investPlan.getImpleProjId());
//		planSet.setImpleProjName(investPlan.getImpleProjName());
		return investPlanQueryDAO.queryInvestPlanSetDetail(param);
	}
	
	@Override
	public PageQuery<InvestStatic> queryInvestPlanStatic(String inJson) {
		if (!JsonUtil.jsonValidate(inJson)) {
			throw new BaseException(
					new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
		}
		// 1.分页信息
		PageQuery<InvestStatic> page = null;
		JSONObject jsonObj = JSONObject.fromObject(inJson);
		if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
			JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
			page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
			jsonObj.remove(MDA.PAGE_QUERY_INFO);
		}
		InvestStatic investStatic = JsonUtil.jsonToBean(jsonObj.toString(), InvestStatic.class);
		
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("investStatic", investStatic);
		if(page != null){
			param.put("page", page);
			PageHelper.startPage(page.getPageNumber(), page.getPageSize());
		}
		// 2.列表查询
		List<InvestStatic> list = investPlanQueryDAO.queryInvestPlanStatic(param);
		// 3.获取项目前期工作情况
		impleProjJoinProjStage(list);
		// 4.获取各项资金
		
		Calendar calendar = Calendar.getInstance();
        String thisYear = String.valueOf(calendar.get(Calendar.YEAR));
        String lastYear = String.valueOf(calendar.get(Calendar.YEAR)-1);
        List<String> objIds = new ArrayList<String>();
        List<String> investPlanIdList = new ArrayList<String>();
        for(InvestStatic is : list){
			String endYear = lastYear;
        	if(is.getStartDt()!=null && !"".equals(is.getStartDt())){
                lastYear = is.getStartDt().trim().substring(0,4);
			}

			// 4.1 概算总投资 -- 实施工程投资累计
        	objIds.clear();
	        objIds.add(is.getImpleProjId());
			FundDetailVo roughTotalInvest = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_IMPLEMENT,objIds,null,null,"10");
			is.setRoughTotalInvest(roughTotalInvest);
			// 4.2 累计至上一年下达计划 实施项目 批复与下达后
			objIds.clear();
			investPlanIdList.clear();
        	InvestPlan ip = new InvestPlan();
            ip.setImpleProjId(is.getImpleProjId());
            ip.setStatusCd(MDA.FUND_PLAN_STATUS_CD_PASS + "");
            Map<String, Object> ipParam = new HashMap<String, Object>();
            ipParam.put("investPlan", ip);
            ipParam.put("page", page);
            List<InvestPlan> ips = investPlanQueryDAO.queryInvestPlanList(ipParam);
            if(!ListUtil.isListEmpty(ips)){
                for(InvestPlan o : ips){
                	investPlanIdList.add(o.getInvestPlanId());
                }
            }
	        FundDetailVo totalIssued = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303,investPlanIdList,null,null,"10");
	        is.setTotalIssued(totalIssued);
	        // 4.2.1 累计至上一年下达的计划--明细
	        List<Funds> totalIssuedFunds = obtainTotalFundsDetail(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303,investPlanIdList,null,null);
	        is.setTotalIssuedFunds(totalIssuedFunds);
	        // 4.3 累计至上一年完成的投资 实施项目 在 固定资产中录入后 各项资金统计
	        objIds.clear();
			FixAsset fa = new FixAsset();
			fa.setImpleProjId(is.getImpleProjId());
			fa.setStatusCd("20");
			param.put("fixAsset", fa);
			List<FixAsset> fixAssets = fixAssetQueryDao.queryFixAssetList(param);
			for (FixAsset fixAsset : fixAssets) {
				objIds.add(fixAsset.getFixAssetId());
			}
			FundDetailVo totalInvest = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_FUND_501, objIds, null, null, "10");
	        is.setTotalInvest(totalInvest);
	        // 4.3.1 累计至上一年完成的投资--明细
	        //List<Funds> totalInvestFunds = obtainTotalFundsDetail(MDA.FUND_SOURCE_OBJ_TYPE_FUND_501,objIds,lastYear,thisYear);
            List<Funds> totalInvestFunds = obtainTotalFundsDetailAsset(MDA.FUND_SOURCE_OBJ_TYPE_FUND_501,objIds,null,null);
	        is.setTotalInvestFunds(totalInvestFunds);
			// 4.4 累计至上一年到位资金
	        objIds.clear();
	        Map<String,Object> inMap = new HashMap<String,Object>();
			inMap.put("impleProjId",is.getImpleProjId());
			inMap.put("statusCd",MDA.FUND_PLAN_STATUS_CD_PASS);
			List<FundPlan> fundPlans = fundPlanQueryDAO.queryFundPlanList(inMap);
			if(!ListUtil.isListEmpty(fundPlans)){
				for(FundPlan f: fundPlans){
	                objIds.add(f.getFundPlanId());
	            }
			}
			FundDetailVo totalFund = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_FUND_403,objIds,null,null,"10");
	        is.setTotalFund(totalFund);
	        // 4.4.1 累计至上一年到位资金--明细
	        List<Funds> totalFundFunds = obtainTotalFundsDetail(MDA.FUND_SOURCE_OBJ_TYPE_FUND_403,objIds,null,null);
	        is.setTotalFundFunds(totalFundFunds);
			// 4.5 当年投资计划
			FundDetailVo investPlan = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303,investPlanIdList,null,null,"10");
			is.setInvestPlan(investPlan);
        }
		// 5.结果返回
		if(page != null){
			page.setTotalPages(((Page<InvestStatic>)list).getPages());
			page.setTotal(((Page<InvestStatic>)list).getTotal());
		}else{
			page = new PageQuery<InvestStatic>();
		}
		page.setRows(list);
		return page;
	}

    private List<Funds> obtainTotalFundsDetailAsset(String objType, List<String> objIds,
                                               String beginYear,String endYear) {
        List<Funds> list = new ArrayList<Funds>();
        if(objIds == null || objIds.size() == 0){
            return list;
        }
        Map<String,Object> inMap = new HashMap<String,Object>();
        inMap.put("objType",objType);
        inMap.put("objIds",objIds);
        inMap.put("beginYear",beginYear);
        inMap.put("endYear",endYear);
        List<Funds> fsList = fundSourceQueryDAO.queryAssetFundsContainYear(inMap);
        return  fsList;
    }
    private List<Funds> obtainTotalFundsDetail(String objType, List<String> objIds,
                                               String beginYear,String endYear) {
        List<Funds> list = new ArrayList<Funds>();
        if(objIds == null || objIds.size() == 0){
            return list;
        }
        Map<String,Object> inMap = new HashMap<String,Object>();
        inMap.put("objType",objType);
        inMap.put("objIds",objIds);
        inMap.put("beginYear",beginYear);
        inMap.put("endYear",endYear);
        List<Funds> fsList = new ArrayList<Funds>();
        if(objType.startsWith("3")){
            fsList = fundSourceQueryDAO.queryInvestPlanFundsContainYear(inMap);
        } else {
            fsList = fundSourceQueryDAO.queryFundPlanFundsContainYear(inMap);
        }
		if (fsList != null && fsList.size() > 0) {
			for (Funds fund : fsList) {
				fund.setBuFund(new BigDecimal(fund.getBuFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setShengFund(
						new BigDecimal(fund.getShengFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setGaoFund(new BigDecimal(fund.getGaoFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setShiFund(new BigDecimal(fund.getShiFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setQiFund(new BigDecimal(fund.getQiFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setOtherFund(
						new BigDecimal(fund.getOtherFund()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
				fund.setTotalFund(fund.getTotalFund().setScale(2, BigDecimal.ROUND_HALF_UP));
			}
		}
        return  fsList;
    }


	private List<Funds> obtainTotalFundsDetail_bk(String objType, List<String> objIds,
			String beginYear,String endYear) {
		List<Funds> list = new ArrayList<Funds>();
		if(objIds == null || objIds.size() == 0){
			return list;
		}
		Map<String,Object> inMap = new HashMap<String,Object>();
	    inMap.put("objType",objType);
        inMap.put("objIds",objIds);
		for (int i = Integer.valueOf(beginYear); i <= Integer.valueOf(endYear); i++) {
			inMap.put("yearDt",i);
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFundsContainYear(inMap);
			Funds fund = new Funds();
			fund.setYear(i + "");
			if (fundSourceList != null && fundSourceList.size() > 0) {
				BigDecimal total = new BigDecimal(0);
				for(FundSource fs : fundSourceList){
					switch (fs.getFundSourceType()) {
					case "10":
						fund.setBuFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					case "20":
						fund.setShengFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					case "30":
						fund.setGaoFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					case "40":
						fund.setShiFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					case "50":
						fund.setQiFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					case "60":
						fund.setOtherFund(Double.parseDouble(fs.getFundVal()));
						total = total.add(new BigDecimal(fs.getFundVal()));
						break;
					default:
						break;
					}
				}
				fund.setTotalFund(total);
			} /*else {
				fund.setBuFund(0d);
				fund.setShengFund(0d);
				fund.setGaoFund(0d);
				fund.setShiFund(0d);
				fund.setQiFund(0d);
				fund.setOtherFund(0d);
				fund.setTotalFund(BigDecimal.valueOf(0));
			}*/
			if(fund.getTotalFund() != null && fund.getTotalFund().compareTo(BigDecimal.valueOf(0)) > 0){
				list.add(fund);
			}
		}
		
		return list;
	}

	public PageQuery<InvestStatic> queryInvestPlanStatic_bak(String inJson) {
		if (!JsonUtil.jsonValidate(inJson)) {
			throw new BaseException(
					new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
		}
		String more = JsonUtil.obtainValueFromJsonObject(inJson, "more");
		
		PageQuery<InvestStatic> page = null;
		JSONObject jsonObj = JSONObject.fromObject(inJson);
		if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
			JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
			page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
			jsonObj.remove(MDA.PAGE_QUERY_INFO);
		}
		InvestStatic investStatic = JsonUtil.jsonToBean(jsonObj.toString(), InvestStatic.class);
		
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("investStatic", investStatic);
		if(page != null){
			param.put("page", page);
			PageHelper.startPage(page.getPageNumber(), page.getPageSize());
		}
		List<InvestStatic> list = investPlanQueryDAO.queryInvestPlanStatic(param);
		if (StringUtils.isNotEmpty(more) && "1".equals(more)) {
			Calendar date = Calendar.getInstance();
			int endyear = date.get(Calendar.YEAR);
			for (InvestStatic staticitem : list) {
				int startyear = Integer.valueOf(staticitem.getStartDt());
				List<Funds> funds = new ArrayList<Funds>();
				for (int i = startyear; i < endyear; i++) {
					Map<String, Object> param2 = new HashMap<String, Object>();
					param2.put("year", i);
					param2.put("impleProjId", staticitem.getImpleProjId());
					List<FundSource> fundSources = investPlanQueryDAO.queryFundsByYear(param2);
					Funds fund = new Funds();
					fund.setYear(i + "");
					if (fundSources != null && fundSources.size() > 0) {
						Double total = 0d;
						for(FundSource fs : fundSources){
							switch (fs.getFundSourceType()) {
							case "10":
								fund.setBuFund(Double.parseDouble(fs.getFundVal()));
								total += Double.parseDouble(fs.getFundVal());
								break;
							case "20":
								fund.setShengFund(Double.parseDouble(fs.getFundVal()));
								total += Double.parseDouble(fs.getFundVal());
								break;
							case "30":
								fund.setGaoFund(Double.parseDouble(fs.getFundVal()));
								total += Double.parseDouble(fs.getFundVal());
								break;
							case "40":
								fund.setShiFund(Double.parseDouble(fs.getFundVal()));
								total += Double.parseDouble(fs.getFundVal());
								break;
							case "50":
								fund.setQiFund(Double.parseDouble(fs.getFundVal()));
								total += Double.parseDouble(fs.getFundVal());
								break;
							default:
								break;
							}
						}
						fund.setTotalFund(BigDecimal.valueOf(total));
					} else {
						fund.setBuFund(0d);
						fund.setShengFund(0d);
						fund.setGaoFund(0d);
						fund.setShiFund(0d);
						fund.setQiFund(0d);
					}
					funds.add(fund);
				}
				staticitem.setFunds(funds);
			}
		}
		
		// 获取项目前期工作情况
		impleProjJoinProjStage(list);
				
		// 3.结果返回
		if(page != null){
			page.setTotalPages(((Page<InvestStatic>)list).getPages());
			page.setTotal(((Page<InvestStatic>)list).getTotal());
		}else{
			page = new PageQuery<InvestStatic>();
		}
		page.setRows(list);
		return page;
	}
	
	/**
	 * 
	 * 实施项目获取项目前期工作情况（项目阶段信息表状态为30）
	 * @param list 
	 */
	private void impleProjJoinProjStage(List<InvestStatic> list) {
		ProjectStage projStage = new ProjectStage();
		projStage.setStatusCd(MDA.PROJECT_STAGE_STATUS_CD_FINISH);//已完工
		for(InvestStatic ip : list){
			projStage.setImpleProjId(ip.getImpleProjId());
			List<ProjectStage> projStageList = implementProjQueryDAO.queryImpleProjStageList(projStage);
			StringBuffer sb =  new StringBuffer();
			for(ProjectStage temp : projStageList){
				sb.append(temp.getProjStateName()).append(":").append(temp.getApprovalInfo()).append(";");
			}
			ip.setPreWorkSituation(sb.toString());
		}
	}

	@Override
	public List<JSONObject> queryProjectAndTotalFoundSource(String impleProjId, String declareType) {
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_IMPLEMENT);// 规划项目
		fundSource.setFundSourceObj(impleProjId);
		List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
		List<JSONObject> list = new ArrayList<JSONObject>();
		JSONObject projectFund=new JSONObject();
		JSONObject totalFund = new JSONObject();
		Double total = 0d;
		for(FundSource fs : fundSourceList){
			switch (fs.getFundSourceType()) {
			case "10":
				projectFund.put("FundBu", Double.parseDouble(fs.getFundVal()));
				total += Double.parseDouble(fs.getFundVal());
				break;
			case "20":
				projectFund.put("FundSheng", Double.parseDouble(fs.getFundVal()));
				total += Double.parseDouble(fs.getFundVal());
				break;
			case "30":
				projectFund.put("FundGao", Double.parseDouble(fs.getFundVal()));
				total += Double.parseDouble(fs.getFundVal());
				break;
			case "40":
				projectFund.put("FundShi", Double.parseDouble(fs.getFundVal()));
				total += Double.parseDouble(fs.getFundVal());
				break;
			case "50":
				projectFund.put("FundQi", Double.parseDouble(fs.getFundVal()));
				total += Double.parseDouble(fs.getFundVal());
				break;
			default:
				break;
			}
		}
		projectFund.put("total", Math.round(total));
		if ("10".equals(declareType)) {
			fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_INVEST);
		} else if ("20".equals(declareType)) {
			fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_FUND);
		}
		InvestStatic sum = fundSourceQueryDAO.queryTotalFoundSourceByProjectId(fundSource);
		if (sum != null) {
			totalFund.put("FundBu", StringUtil.getNoNullDouble(sum.getBuFund()));
			totalFund.put("FundSheng", StringUtil.getNoNullDouble(sum.getShengFund()));
			totalFund.put("FundGao", StringUtil.getNoNullDouble(sum.getGaoFund()));
			totalFund.put("FundShi", StringUtil.getNoNullDouble(sum.getShiFund()));
			totalFund.put("FundQi", StringUtil.getNoNullDouble(sum.getQiFund()));
			totalFund.put("total", StringUtil.getNoNullDouble(sum.getTotal()));
		} else {
			totalFund.put("FundBu", StringUtil.getNoNullDouble(0));
			totalFund.put("FundSheng", StringUtil.getNoNullDouble(0));
			totalFund.put("FundGao", StringUtil.getNoNullDouble(0));
			totalFund.put("FundShi", StringUtil.getNoNullDouble(0));
			totalFund.put("FundQi", StringUtil.getNoNullDouble(0));
			totalFund.put("total", StringUtil.getNoNullDouble(0));
		}
		list.add(projectFund);
		list.add(totalFund);
		return list;
	}

	@Override
	public List<PlanDeclareSet> queryDeclareSetIdsForList(String declareType) {
//		Map<String, String> result = new HashMap<String, String>();
		List<PlanDeclareSet> list = investPlanQueryDAO.queryPlanDeclareSets(declareType);
//		if (list != null && list.size() > 0) {
//			for (PlanDeclareSet planDeclareSet : list) {
//				result.put(planDeclareSet.getDeclareSetId(), planDeclareSet.getDeclareCode());
//			}
//		}
		return list;
	}
	@Override
	public Map<String,String> queryDeclareSetIds(String declareType) {
		Map<String, String> result = new HashMap<String, String>();
		List<PlanDeclareSet> list = investPlanQueryDAO.queryPlanDeclareSets(declareType);
		if (list != null && list.size() > 0) {
			for (PlanDeclareSet planDeclareSet : list) {
				result.put(planDeclareSet.getDeclareSetId(), planDeclareSet.getDeclareCode());
			}
		}
		return result;
	}

	/**
	 * 概预算是规划工程对应的数据, 10：规划项目
	 * 下达计划是项目对应的数据,  20：实施项目
	 * 投资就是投资计划 30：投资计划
	 * 到位资金就是资金计划 40：资金计划
	 * 资金来源类型10:部补助;  20:省财政; 30:高速水运融资; 40:市州配套; 50:企业自筹
	 */
	public FundDetailVo getEachMoney(String objType,List<String> objIds,String beginYear,String endYear,String statusCd){
		FundDetailVo vo = new FundDetailVo();
		vo.setFundBu("0");
		vo.setFundSheng("0");
		vo.setFundGao("0");
		vo.setFundShi("0");
		vo.setFundQi("0");
		vo.setFundOther("0");
		vo.setTotal("0");
		if(objIds == null || objIds.size() == 0){
			return vo;
		}
	    Map<String,Object> inMap = new HashMap<String,Object>();
	    inMap.put("objType",objType);
        inMap.put("objIds",objIds);
        inMap.put("statusCd",statusCd);
        if(beginYear!=null){
            inMap.put("beginYear",beginYear);
        }
        inMap.put("endYear",endYear);
        List<FundSource> fundSourceList = fundSourceQueryDAO.queryFundsDetailByParam(inMap);
		BigDecimal total = new BigDecimal(0);
		BigDecimal buSum = new BigDecimal(0);
		BigDecimal shengSum = new BigDecimal(0);
		BigDecimal gaoSum = new BigDecimal(0);
		BigDecimal shiSum = new BigDecimal(0);
		BigDecimal qiSum = new BigDecimal(0);
		BigDecimal otherSum = new BigDecimal(0);

		for(FundSource fs : fundSourceList) {
			switch (fs.getFundSourceType()) {
				case "10":
				buSum = buSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				case "20":
				shengSum = shengSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				case "30":
				gaoSum = gaoSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				case "40":
				shiSum = shiSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				case "50":
				qiSum = qiSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				case "60":
				otherSum = otherSum.add(new BigDecimal(fs.getFundVal()).setScale(2, BigDecimal.ROUND_HALF_UP));
					break;
				default:
					break;
			}
		}
		total = total.add(buSum).add(shengSum).add(gaoSum).add(shiSum).add(qiSum).add(otherSum);
		vo.setFundBu(buSum.toPlainString());
		vo.setFundSheng(shengSum.toPlainString());
		vo.setFundGao(gaoSum.toPlainString());
		vo.setFundShi(shiSum.toPlainString());
		vo.setFundQi(qiSum.toPlainString());
		vo.setFundOther(otherSum.toPlainString());
		vo.setTotal(total.toPlainString());
        return vo;
	}

	private List<FundDetailVo> getTotalBaseFunds() {
		List<FundDetailVo> total = new ArrayList<FundDetailVo>();
		FundDetailVo planProjMoney = getEachMoney(null, null, null, null, null);
		planProjMoney.setType("planProjMoney");
		total.add(planProjMoney);
		FundDetailVo implProjMoney = getEachMoney(null, null, null, null, null);
		implProjMoney.setType("implProjMoney");
		total.add(implProjMoney);
		FundDetailVo investPlanMoney = getEachMoney(null, null, null, null, null);
		investPlanMoney.setType("investPlanMoney");
		total.add(investPlanMoney);
		FundDetailVo fundPlanMoney = getEachMoney(null, null, null, null, null);
		fundPlanMoney.setType("fundPlanMoney");
		total.add(fundPlanMoney);
		FundDetailVo fundWriteMoney = getEachMoney(null, null, null, null, null);
		fundWriteMoney.setType("fundWriteMoney");
		total.add(fundWriteMoney);
		FundDetailVo fundFirstMoney = getEachMoney(null, null, null, null, null);
		fundFirstMoney.setType("fundFirstMoney");
		total.add(fundFirstMoney);
		FundDetailVo fundEndMoney = getEachMoney(null, null, null, null, null);
		fundEndMoney.setType("fundEndMoney");
		total.add(fundEndMoney);
		return total;
	}

    @Override
    public PageQuery<InvestPlanRspVo> queryInvestPlanListNew(String inJson, List<String> typelist) throws Exception {
        PageQuery<InvestPlanRspVo> page = JsonUtil.jsonToBean(inJson, PageQuery.class);
        List<InvestPlanRspVo> ls = new ArrayList<InvestPlanRspVo>();

        //InvestPlan iPlan = JsonUtil.jsonToBean(inJson, InvestPlan.class);
		JSONObject jo = JSONObject.fromObject(inJson);
		String declareSetId =  JsonUtil.obtainValueFromJsonObject(inJson,"declareSetId");
		String impleProjId = JsonUtil.obtainValueFromJsonObject(inJson,"impleProjId");
		String developOrg = JsonUtil.obtainValueFromJsonObject(inJson, "developOrg");

        String staffCode = JsonUtil.obtainValueFromJsonObject(inJson, "staffCode");
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("declareSetId", declareSetId);
        param.put("impleProjId", impleProjId);
        param.put("orgId", developOrg);
		param.put("typelist", typelist);
		List<InvestPlan> allinvestPlans = investPlanQueryDAO.queryInvestPlanListNew(param);
        PageHelper.startPage(page.getPageNumber(), page.getPageSize());
        List<InvestPlan> investPlans = investPlanQueryDAO.queryInvestPlanListNew(param);
		InvestPlanRspVo totalvo = new InvestPlanRspVo();
		List<FundDetailVo> totalfunds = getTotalBaseFunds();
		totalvo.setFundDetailVo(totalfunds);
		List<String> investplanIds = new ArrayList<String>();
        for (InvestPlan investPlan : investPlans) {
			investplanIds.add(investPlan.getInvestPlanId());
			// 前期工作情况组装
			ProjectStage projStage = new ProjectStage();
			projStage.setStatusCd(MDA.PROJECT_STAGE_STATUS_CD_FINISH);// 已完工
			projStage.setImpleProjId(investPlan.getImpleProjId());
			List<ProjectStage> projStageList = implementProjQueryDAO.queryImpleProjStageList(projStage);
			StringBuffer sb = new StringBuffer();
			for (ProjectStage temp : projStageList) {
				sb.append(temp.getProjStateName()).append(":").append(temp.getApprovalInfo()).append(";");
			}
			investPlan.setPreWorkSituation(sb.toString());
			// 概算+三项累计查询
			List<FundDetailVo> fundDetailVos = queryFourFundSource(investPlan.getImpleProjId(),
					investPlan.getInvestPlanId(), null);
			for (FundDetailVo fundDetailVo : fundDetailVos) {
				fundDetailVo.setYearDt((Integer.valueOf(investPlan.getYearDt()) - 1) + "");
			}
			// 5、****年填报投资计划 当年 计划填报 金额
			List<String> objIds = new ArrayList<String>();
			objIds.add(investPlan.getInvestPlanId());
			FundDetailVo fundWriteMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_301, objIds, null, null, "10");
            fundWriteMoney.setType("fundWriteMoney");
            fundWriteMoney.setRemark(investPlan.getDescription());
			fundWriteMoney.setYearDt(investPlan.getYearDt());
            fundDetailVos.add(fundWriteMoney);

			// 6、 ****年初审投资计划 当年 计划初审 金额
			FundDetailVo fundFirstMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_302, objIds, null, null, "10");
            fundFirstMoney.setType("fundFirstMoney");
            fundFirstMoney.setRemark(investPlan.getExamineDescription());
            Map<String, Object> paramfile = new HashMap<String, Object>();
            paramfile.put("uploadObjId", investPlan.getInvestPlanId());
            paramfile.put("uploadObjType", "130");
            List<FileVo> files = fundPlanQueryDAO.queryFileListUploadsByCond(paramfile);
            if(!ListUtil.isListEmpty(files)){
                investPlan.setFiles(files);
                String fileNames ="";
                for(FileVo f:files){
                    fileNames=fileNames + f.getAttachFullName()+"   ";
                }
                fundFirstMoney.setFileName(fileNames);
            }
			fundFirstMoney.setYearDt(investPlan.getYearDt());
            fundDetailVos.add(fundFirstMoney);


			// 7、 ****年批复投资计划 当年 计划初审 金额
			FundDetailVo fundEndMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303, objIds, null, null, "10");
            fundEndMoney.setType("fundEndMoney");
            fundEndMoney.setRemark("");

            paramfile.clear();;
            paramfile.put("uploadObjId", investPlan.getInvestPlanId());
            paramfile.put("uploadObjType", "150");
            List<FileVo> files1 = fundPlanQueryDAO.queryFileListUploadsByCond(paramfile);
            if(!ListUtil.isListEmpty(files1)){
                investPlan.setFiles(files1);
                String fileNames ="";
                for(FileVo f:files1){
                    fileNames=fileNames + f.getAttachFullName()+"   ";
                }
                fundEndMoney.setFileName(fileNames);
            }
			fundEndMoney.setYearDt(investPlan.getYearDt());
            fundDetailVos.add(fundEndMoney);

            InvestPlanRspVo vo = new InvestPlanRspVo();
            BeanUtils.copyProperties(investPlan,vo);
            vo.setFundDetailVo(fundDetailVos);
            ls.add(vo);
				for (FundDetailVo t1 : totalvo.getFundDetailVo()) {
					for (FundDetailVo t2 : fundDetailVos) {
						if (t1.getType().equals(t2.getType())) {
							t1.setFundBu(new BigDecimal(t1.getFundBu()).add(new BigDecimal(t2.getFundBu()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setFundSheng(new BigDecimal(t1.getFundSheng()).add(new BigDecimal(t2.getFundSheng()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setFundGao(new BigDecimal(t1.getFundGao()).add(new BigDecimal(t2.getFundGao()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setFundShi(new BigDecimal(t1.getFundShi()).add(new BigDecimal(t2.getFundShi()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setFundQi(new BigDecimal(t1.getFundQi()).add(new BigDecimal(t2.getFundQi()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setFundOther(new BigDecimal(t1.getFundOther()).add(new BigDecimal(t2.getFundOther()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							t1.setTotal(new BigDecimal(t1.getTotal()).add(new BigDecimal(t2.getTotal()))
									.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
						}
					}
				}
        }
		// 总数大于当前页数时，统计后面的数据
		if (investPlans != null && investPlans.size() < allinvestPlans.size()) {
			List<InvestPlan> nextlist = new ArrayList<>();
			for (InvestPlan vo : allinvestPlans) {
				if (!investplanIds.contains(vo.getInvestPlanId())) {
					nextlist.add(vo);
				}
			}
			for (InvestPlan investPlan : nextlist) {
				// 概算+三项累计查询
				List<FundDetailVo> fundDetailVos = queryFourFundSource(investPlan.getImpleProjId(),
						investPlan.getInvestPlanId(), null);
				for (FundDetailVo fundDetailVo : fundDetailVos) {
					fundDetailVo.setYearDt((Integer.valueOf(investPlan.getYearDt()) - 1) + "");
				}
				// 5、****年填报投资计划 当年 计划填报 金额
				List<String> objIds = new ArrayList<String>();
				objIds.add(investPlan.getInvestPlanId());
				FundDetailVo fundWriteMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_301, objIds, null, null,
						"10");
				fundWriteMoney.setType("fundWriteMoney");
				fundWriteMoney.setRemark(investPlan.getDescription());
				fundWriteMoney.setYearDt(investPlan.getYearDt());
				fundDetailVos.add(fundWriteMoney);

				// 6、 ****年初审投资计划 当年 计划初审 金额
				FundDetailVo fundFirstMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_302, objIds, null, null,
						"10");
				fundFirstMoney.setType("fundFirstMoney");
				fundFirstMoney.setRemark(investPlan.getExamineDescription());
				fundFirstMoney.setYearDt(investPlan.getYearDt());
				fundDetailVos.add(fundFirstMoney);

				// 7、 ****年批复投资计划 当年 计划初审 金额
				FundDetailVo fundEndMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303, objIds, null, null, "10");
				fundEndMoney.setType("fundEndMoney");
				fundEndMoney.setRemark("");

				fundEndMoney.setYearDt(investPlan.getYearDt());
				fundDetailVos.add(fundEndMoney);
					for (FundDetailVo t1 : totalvo.getFundDetailVo()) {
						for (FundDetailVo t2 : fundDetailVos) {
							if (t1.getType().equals(t2.getType())) {
								t1.setFundBu(new BigDecimal(t1.getFundBu()).add(new BigDecimal(t2.getFundBu()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setFundSheng(new BigDecimal(t1.getFundSheng()).add(new BigDecimal(t2.getFundSheng()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setFundGao(new BigDecimal(t1.getFundGao()).add(new BigDecimal(t2.getFundGao()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setFundShi(new BigDecimal(t1.getFundShi()).add(new BigDecimal(t2.getFundShi()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setFundQi(new BigDecimal(t1.getFundQi()).add(new BigDecimal(t2.getFundQi()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setFundOther(new BigDecimal(t1.getFundOther()).add(new BigDecimal(t2.getFundOther()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
								t1.setTotal(new BigDecimal(t1.getTotal()).add(new BigDecimal(t2.getTotal()))
										.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
							}
						}
					}
			}
		}
		if (typelist.size() > 1) {
			totalvo.setStatusCd(MDA.FUND_PLAN_STATUS_CD_PASS.toString());
			ls.add(totalvo);

		}
        page.setRows(ls);
        page.setTotalPages(((Page<InvestPlan>) investPlans).getPages());
        page.setTotal(((Page<InvestPlan>)investPlans).getTotal());
        return page;
    }



    public InvestPlanRspVo queryInvestPlanForGreen(String inJson) throws Exception{
        InvestPlanRspVo vo = new InvestPlanRspVo();
        JSONObject jo = JSONObject.fromObject(inJson);
        String impleProjId = JsonUtil.getNotNullStringFromJSON(jo,"impleProjId","");
		String investPlanId = JsonUtil.getStringFromJSON(jo, "investPlanId", "");
		String yearDt = null;
		if (StringUtils.isEmpty(investPlanId)) {
			yearDt = "yearDt";
		}
		List<FundDetailVo> fundDetailVos = queryFourFundSource(impleProjId, investPlanId, yearDt);
        vo.setFundDetailVo(fundDetailVos);
	    return vo;
    }

	/**
	 * 
	 * @param impleProjId:实施项目Id
	 * @param fundSourceObjId:统计时不用统计的投资（资金）计划ID
	 * @param yearDt:累计至****年
	 * @return
	 */
	public List<FundDetailVo> queryFourFundSource(String impleProjId, String fundSourceObjId,
			String yearDt) {
		List<FundDetailVo> fundDetailVos = new ArrayList<FundDetailVo>();

		// 1、概算总投资 实施项目资金
		List<String> objIds = new ArrayList<String>();
		objIds.add(impleProjId);
		FundDetailVo planProjMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_IMPLEMENT, objIds, null, null, "10");
		planProjMoney.setType("planProjMoney");
		fundDetailVos.add(planProjMoney);

		// 2、累计至****年下达计划 实施项目 批复与下达后
		// 各项资金统计；（如：累计2017，包括2017申报批次，2016年申报批次，2015年申报批次 累计 实施项目各个批次
		// 批复与下达完后的各项资金统计 ）。
		objIds.clear();
		Map<String, Object> param = new HashMap<String, Object>();
		InvestPlan ip = new InvestPlan();
		ip.setImpleProjId(impleProjId);
		ip.setStatusCd("60");
		ip.setYearDt(yearDt);
		param.put("investPlan", ip);
		param.put("fundSourceObjId", fundSourceObjId);
		List<InvestPlan> ips = investPlanQueryDAO.queryInvestPlanList(param);
		if (!ListUtil.isListEmpty(ips)) {
			for (InvestPlan o : ips) {
				if (o.getInvestPlanId() != null && o.getInvestPlanId().equals(fundSourceObjId)) {
					continue;
				}
				objIds.add(o.getInvestPlanId());
			}
		}
		FundDetailVo implProjMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_INVEST_303, objIds, null, null, "10");
		implProjMoney.setType("implProjMoney");
		fundDetailVos.add(implProjMoney);

		// 3、累计至****年完成投资 实施项目 在 固定资产中录入后 各项资金统计
		objIds.clear();
		param.clear();
		FixAsset fa = new FixAsset();
		fa.setImpleProjId(impleProjId);
		fa.setStatusCd("20");
		param.put("fixAsset", fa);
		List<FixAsset> fixAssets = fixAssetQueryDao.queryFixAssetList(param);
		for (FixAsset fixAsset : fixAssets) {
			objIds.add(fixAsset.getFixAssetId());
		}
		FundDetailVo investPlanMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_FUND_501, objIds, null, null, "10");
		investPlanMoney.setType("investPlanMoney");
		fundDetailVos.add(investPlanMoney);

		// 4 到位资金就是资金计划 40：资金计划 根据 impleProjId 查资金计划表
		FundDetailVo fundPlanMoney = new FundDetailVo();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("impleProjId", impleProjId);
		inMap.put("statusCd", "60");
		inMap.put("fundSourceObjId", fundSourceObjId);
		inMap.put("yearDt", yearDt);
		List<FundPlan> fundPlans = fundPlanQueryDAO.queryFundPlanList(inMap);
		objIds.clear();
		if (!ListUtil.isListEmpty(fundPlans)) {
			for (FundPlan f : fundPlans) {
				if (f.getFundPlanId() != null && f.getFundPlanId().equals(fundSourceObjId)) {
					continue;
				}
				objIds.add(f.getFundPlanId());
			}
		}
		fundPlanMoney = getEachMoney(MDA.FUND_SOURCE_OBJ_TYPE_FUND_403, objIds, null, null, "10");
		fundPlanMoney.setType("fundPlanMoney");
		fundDetailVos.add(fundPlanMoney);
		return fundDetailVos;
	}

	@Override
	public List<String> queryExistedImpleProjList(String inJson) throws Exception {
		JSONObject json = JSONObject.fromObject(inJson);
		String declareSetId = JsonUtil.getNotNullStringFromJSON(json, "declareSetId", "");
		List<String> list = investPlanQueryDAO.queryExistedImpleProjList(declareSetId);
		return list;
	}

}
